package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-07-21 9:38
 */
public class Solution_0504 {
    /**
     * @param num
     * @return
     */
    public String convertToBase7(int num) {
        if (num > 0) return this.change(num);
        else if (num == 0) return "0";
        else {
            return "-" + this.change(-num);
        }
    }

    public String change(int num) {
        String res = "";
        while (num > 0) {
            res = num % 7 + res;
            num /= 7;
        }
        return res;
    }
}
